﻿using CefSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows;
using System.Windows.Forms;

namespace WPF
{


    class CefDownloadHandler : IDownloadHandler
    {
        private readonly string _path;
        private Stream _stream;

        public CefDownloadHandler(string fileName)
        {
            FolderBrowserDialog path = new FolderBrowserDialog();
            path.ShowDialog();
            string strPath = path.SelectedPath;
            //System.Windows.MessageBox.Show(strPath);
            // _path = Path.Combine(Path.GetTempPath(), fileName);
            _path = Path.Combine(strPath, fileName);


            _stream = File.Create(_path);
        }

        public bool ReceivedData(byte[] data)
        {
            _stream.Write(data, 0, data.GetLength(0));
            return true;

        }
        public void Complete()
        {
            _stream.Dispose();
            _stream = null;
            String strMsg = String.Format("完成下载，地址: {0}", _path);
            System.Windows.Forms.MessageBox.Show(strMsg);
        }

    }
}
